//商品列表
var app = getApp(); //全局APP

Page({
	//页面的初始数据
	data: {
		listData: [],
		showData: []
	},

	//加载执行
	onLoad: function(options) {
		this.getWrongStudent();
	},
	
	//加载执行
	onShow: function() {
	},
	
	getWrongStudent: function() {
		var page = this;
		
		// 获取班级
		app.api.getWrongStudent(function(res) {
			if (res.status) {
				page.setData({
					listData: res.data,
					showData: res.data
				});
			} else {
				//报错了
				app.common.errorToBack(res.msg, 0);
				page.setData({
					listData: [],
					showData: []
				});
			}
		});
	},
	 
	inputTyping: function(e) {
		if (e.detail.value !== '') {
			var actionArr = this.data.listData;
			var val = e.detail.value;
			var temp = []; 
			
			actionArr.forEach(function(i) {
				var xm = i.xm;
				var xh = i.xh;
				if (xm.indexOf(val) != -1 || xh.indexOf(val) != -1) {
					temp.push(i);
				}
			});
			
			this.setData({
				showData: temp,
			})
		} else {
			this.setData({
				showData: this.data.listData,
			})
		}
	},
	
	// 隐藏搜索框样式
	hideInput: function() {
		this.setData({
			inputVal: "",
			inputShowed: false,
			showData: this.data.listData
		});
	},
	
	// 接收学生
	receive: function(e) {
		var page = this;
		var data = {
			xh: e.currentTarget.dataset.xh
		};
		
		// 获取班级
		app.api.receive(data, function(res) {
			if (res.status) {
				app.common.successToShow(res.msg, function() {
					page.getWrongStudent();
				}); 
			} else {
				//报错了
				app.common.errorToBack(res.msg, 0);
			}
		});
	},
});
